package org.openrbac.rbac.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.openrbac.rbac.entity.Product;

import java.util.List;

/**
* @author 梁富贵
* @description 针对表【product】的数据库操作Mapper
* @createDate 2024-05-15 20:45:59
* @Entity org.openrbac.rbac.entity.Product
*/
@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    /**
     * 根据商品名查询id，价格，品牌名和供应商
     * @return
     */
    @Select("select id,price,brand_id,supplier_id from product where id = #{name}")
    Product getProductsByname(@Param("name") Integer name);

    /**
     * 获取商品的标题，content
     * @return
     */
    @Select("select product.content,product.price from img_pro left join product on img_pro.pid = product.id " +
            "where img_pro.type = 'normal'")
    List<Product> getRecommandGoods();

    @Select("<script>"+
            "select distinct * from product where id in" +
            "<foreach collection='ids' item='item' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<Product> getProducts(@Param("ids") List<Integer> ids);

    @Select("select distinct img_pro.pid from img_pro where type= #{type} ")
    List<Integer> getRecommandGoodsIds(@Param("type") String type);

    @Select("select distinct img_pro.iid from img_pro where type= #{type} ")
    List<Integer> getRecommandImageIds(@Param("type") String type);
}




